<template>
  <div>
    <h3>欢迎{{username}}</h3>
    <el-button @click="signOut">注销</el-button>
  </div>
  
</template>

<script>
export default {
  name: 'Main' ,
  data(){
    return {
      username: ''
    }
  },
  // 组件内守卫
  beforeRouteEnter(){
    let username = sessionStorage.getItem( 'username' );
    if( !username ) {
      return { name: 'signIn' };
    }
  },
  created(){
    let username = sessionStorage.getItem( 'username' );
    console.log( sessionStorage );
    this.username = username ;
  },
  methods: {
    signOut(){
      sessionStorage.removeItem( 'username' );
      this.$router.push( { name: 'signIn' } )
    }
  }
}
</script>

<style>

</style>